var currentIndex;
$(document).ready(function(){
	initTagArticle();
	active();
});
//获取tags的ajax,时间排序
function getTagByTime(){
	var url = "/HyperIT/tag/findTag";
	var parm = "";
	$.get(url,function(data){
		if (data.serviceResult) {
			var taglist = data.resultParm.taglist;
			showTags(taglist);
		} else{
			messageTip(data.resultInfo);
		}
	});
}
//绘制
function showTags(tags){
	for(var i = 0; i<tags.length; i++){
		$(".tags ul").append('<li>'+
								'<a href="thetag.html?'+tags[i].id+'">'+tags[i].name+'</a>'+
								'<span>'+tags[i].article+'+'+tags[i].question+'</span>'+
							'</li>');
	}
}
function getTagByArticle(index){
	var url = "/HyperIT/tag/findTagByArticleNum";
	var parm = "size=100&indexPageNum="+index;
	$.get(url,parm,function(data){
		if (data.serviceResult) {
			var taglist = data.resultParm.taglist;
			showTags(taglist);
			currentIndex++;
		} else{
			messageTip(data.resultInfo);
		}
	});
}
function getTagByQuestion(index){
	var url = "/HyperIT/tag/findTagByQuestionNum";
	var parm = "size=100&indexPageNum="+index;
	$.get(url,parm,function(data){
		if (data.serviceResult) {
			var taglist = data.resultParm.taglist;
			showTags(taglist);
			currentIndex++;
		} else{
			messageTip(data.resultInfo);
		}
	});
}
function getTagByKey(){
	if($("#tagSearch").val().trim()==""){
		messageTip("请输入标签的关键字");
	}else{
		$(".tags ul>li").remove();
		var url = "/HyperIT/tag/searchTag";
		var parm = "size=100&indexPageNum=1&tag="+$("#tagSearch").val();
		$.get(url,parm,function(data){
			if (data.serviceResult) {
				var taglist = data.resultParm.taglist;
				showTags(taglist);
				currentIndex++;
			} else{
				messageTip(data.resultInfo);
			}
		});
	}
}
function initTagArticle(){
	$(".tags ul>li").remove();
	currentIndex = 1;
	getTagByArticle(currentIndex);
}
function initTagQuestion(){
	$(".tags ul>li").remove();
	currentIndex = 1;
	getTagByQuestion(currentIndex);
}
function initTagTime(){
	$(".tags ul>li").remove();
	currentIndex = 1;
	getTagByTime(currentIndex);
}
function getMore(){
	if($(".selector-group").eq(1).children("ul").children("li.active").children("a").text()=="多文"){
		getTagByArticle(currentIndex);
	}else if($(".selector-group").eq(1).children("ul").children("li.active").children("a").text()=="多问"){
		getTagByQuestion(currentIndex);
	}else{
		getTagByTime(currentIndex);
	}
}
function active(){
	$(".selector-group").eq(1).children("ul").children("li").click(function(){
		$(this).addClass("active").siblings().removeClass("active");
	});
}
